package main

import "fmt"

func main() {
	list := []int{1, 10, 2, 7, 3, 544, 67, 45, 7, 34, 56}
	quickSort(list, 0, len(list)-1)
	fmt.Println(list)
}

func quickSort(list []int, left, right int) {
	if len(list) < 2 {
		return
	}
	if right > left {
		mid := getMidPostion(list, left, right)
		quickSort(list, left, mid)
		quickSort(list, mid+1, right)
	}
}

func getMidPostion(list []int, left, right int) int {
	mark := list[left]
	for right > left {
		for right > left && list[right] > mark {
			right--
		}
		if right > left {
			list[left] = list[right]
			left++
		}
		for right > left && list[left] < mark {
			left++
		}
		if right > left {
			list[right] = list[left]
			right--
		}
	}
	list[left] = mark
	return left
}
